package com.himiotech.core.project.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.himiotech.core.project.data.mapper.JobLogMapper;
import com.himiotech.core.project.model.entity.job.JobLog;
import com.himiotech.core.project.model.metadata.JobLogMetadata;
import com.himiotech.core.project.service.IJobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 定时任务调度日志信息 服务层
 *
 * @author ruoyi
 * @author wuwenbin
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class JobLogServiceImpl extends ServiceImpl<JobLogMapper, JobLog> implements IJobLogService {

    @Autowired
    private JobLogMapper jobLogMapper;

    /**
     * 查询分页数据
     *
     * @param page   分页信息
     * @param jobLog 业务信息查询条件
     * @return 分页对象及数据
     */
    @Override
    public Page<JobLog> selectJobLogListPage(Page<JobLog> page, JobLog jobLog) {
        QueryWrapper<JobLog> query = Wrappers.query();
        query.like(ObjectUtil.isNotEmpty(jobLog.getJobName()), JobLogMetadata.JOB_NAME.getColName(), jobLog.getJobName());
        query.eq(ObjectUtil.isNotEmpty(jobLog.getJobGroup()), JobLogMetadata.JOB_GROUP.getColName(), jobLog.getJobGroup());

        page = jobLogMapper.selectPage(page, query);
        return page;
    }


    /**
     * 清空任务日志
     */
    @Override
    public void cleanJobLog() {
        jobLogMapper.cleanJobLog();
    }
}
